package class01;

/**
 * @description: 计算一个数的阶乘和
 * @time: 2021/7/2 14:13
 * @author: lhy
 */
public class SumOfFactorial {
    public static long f1(int n){
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += factorial(i);
        }
        return sum;
    }

    public static long factorial(int n){
        long res = 1;
        for (int i = 1; i <= n; i++) {
            res *= i;
        }
        return res;
    }

    public static long f2(int n){
        long sum = 0;
        long cur = 1;
        for (int i = 1; i <= n; i++) {
            cur = cur * i;
            sum += cur;
        }
        return sum;
    }

    public static void main(String[] args) {
        System.out.println(f1(4));
        System.out.println(f2(4));
    }
}
